package com.shengzai.hbase;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

import java.io.IOException;

public class DeleteTable {
    public static void main(String[] args) throws IOException {
        Configuration conf = new Configuration();
        conf.set("hbase.zookeeper.quorum","master,node1,node2");
        Connection connection = ConnectionFactory.createConnection(conf);

        Admin admin = connection.getAdmin();
        TableName tableName = TableName.valueOf("api_test:dianxin");
        boolean exists = admin.tableExists(tableName);
        if (exists){
            admin.disableTable(tableName);
            System.out.println(tableName.getNameAsString()+"表已经停用");
            admin.deleteTable(tableName);
            System.out.println(tableName.getNameAsString()+"表已经删除");
        }else
            System.out.println(tableName.getNameAsString()+"表不存在");

    }
}
